home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / PROGRAMM / ASSEMBLE / H235A.ZIP / ASM_0_M.ZIP / KAOSHIDE.ASM < prev    next >
Assembly Source File  |  1990-06-04  |  9KB  |  313 lines

  1.   
  2. ;██████████████████████████████████████████████████████████████████████████
  3. ;██                                                                      ██
  4. ;██                          Hidden Kaos v1.0                            ██
  5. ;██                                                                      ██
  6. ;██        Copyright (C) 1990  Philip Maland  All Rights Reserved        ██
  7. ;██                                                                      ██
  8. ;██                        Created:  June 3, 1990                        ██
  9. ;██                                                                      ██
  10. ;██████████████████████████████████████████████████████████████████████████
  11.   
  12.   
  13. Seg_a        Segment
  14.         Assume    cs:Seg_A, ds:Seg_A
  15.   
  16.   
  17.         org    100h
  18.   
  19. Start:
  20.         jmp    Install            ; Go to installation routine
  21.  
  22. ;██████████████████████████████████████████████████████████████████████████
  23. ;██  Int 09h - New Handler                                               ██   
  24. ;██████████████████████████████████████████████████████████████████████████
  25.  
  26. Int_09:
  27.         push    ax            ; Save the world
  28.         push    bx
  29.         push    cx
  30.         push    dx
  31.         push    es
  32.         pushf
  33.  
  34.         in    al,60h            ; Get scan of code key pressed
  35.                         ; into AL
  36.         mov    bl,32h            ; High char to check ('Z')
  37.         mov    bh,10h            ; Low char to check  ('A')
  38.         call    ChrRang            ; Is AL between 'Z' and 'A'?
  39.         jc    End_09            ; No, it isn't an alpha key
  40.  
  41.         mov    bl,1Dh            ; High char
  42.         mov    bh,1Ah            ; Low char
  43.         call    ChrRang            ; Since we are using scan codes
  44.                         ; there are some keys between
  45.                         ; 'A' and 'Z' that aren't alpha
  46.                         ; keys.  This check for one
  47.                         ; set of non-alpha keys.
  48.  
  49.         jnc    End_09            ; Yes, it isn't an alpha key
  50.  
  51.         mov    bl,2Bh            ; High char
  52.         mov    bh,27h            ; Low char
  53.         call    ChrRang            ; This checks for the other set
  54.                         ; of non-alpha keys.
  55.  
  56.         jnc    End_09            ; Yes, it is in this set, so it
  57.                         ; isn't an alpha key.
  58.         
  59.         mov    ax,10            ; Get random number between 1
  60.         push    ax            ; and 10 and push it on the stack
  61.         call    Random            ; Random number between 1 and 
  62.                         ; 10 is returned in AX
  63.         cmp    ax,5            ; Is the number greater than 5?
  64.         jg    End_09            ; Yes, so leave the key alone
  65.  
  66.         mov    ax,0            ; Point ES to low memory (0000)
  67.         mov    es,ax
  68.         mov    al,byte ptr es:[417h]    ; Get shift flags
  69.         test    al,3            ; Are any of the shift keys pressed?
  70.         jz    SetShift        ; If not, turn on the shift flag
  71.                         ; for the right shift key.
  72. ;█
  73. ;  Here we know a shift key is pressed.
  74. ;█
  75.         mov    cs:SaveShift,al        ; Save the shift flags
  76.  
  77.         and    byte ptr es:[417h],11111100b    ; Clear the shift key
  78.                             ; flags.
  79.         jmp    CallRest
  80.  
  81. SetShift:
  82.         mov    cs:SaveShift,al        ; Save the shift flags
  83.         or    byte ptr es:[417h],01    ; Set the right shift key flag
  84.         jmp    CallRest
  85.  
  86. CallRest:
  87.         popf                ; Restore all registers
  88.         pop    es            ; and call the Int 09h handler
  89.         pop    dx
  90.         pop    cx
  91.         pop    bx
  92.         pop    ax
  93.         pushf
  94.         call    dword ptr cs:[Old_09_Ofs]
  95.  
  96.         push    ax            ; Save the regs were gonna use
  97.         push    es
  98.         pushf
  99.  
  100.         mov    ax,0            ; Point ES to low memory again
  101.         mov    es,ax
  102.         mov    al,cs:SaveShift        ; Get the saved flags
  103.         mov    byte ptr es:[417h],al    ; Restore them back to the
  104.                         ; flag status byte in low memory.
  105.  
  106.         popf                ; Restore the registers
  107.         pop    es
  108.         pop    ax
  109.         iret                ; Return from the interrupt
  110.  
  111. End_09:
  112.         popf                ; Restore all registers
  113.         pop    es
  114.         pop    dx
  115.         pop    cx
  116.         pop    bx
  117.         pop    ax
  118.                         ; Jump to the old Int 09
  119.                         ; handler
  120.         db    0EAh
  121. Old_09_Ofs    dw    0
  122. Old_09_Seg    dw    0
  123.  
  124. SaveShift    db    0            ; Byte to save flags to
  125.  
  126. ;█████████████████████████████████████████████████████████████████████████████
  127. ;██                                                                         ██
  128. ;██   Procedure:  ChrRang                                                   ██
  129. ;██                                                                         ██
  130. ;██   Call to test if a character is between or included by two characters  ██
  131. ;██                                                                         ██
  132. ;██     To Call:     AL = Char to check                                     ██
  133. ;██                  BL = upper match char                                  ██
  134. ;██                  BH = low match char                                    ██
  135. ;██        Exit:     CF clear if valid match                                ██
  136. ;██                  BL = undefined                                         ██
  137. ;██                       all other registers unchanged                     ██
  138. ;██                                                                         ██
  139. ;█████████████████████████████████████████████████████████████████████████████
  140.  
  141. ChrRang:
  142.         cmp    al,bh        ; Is the char < BH
  143.         jc    ChrRng1        ; Yes, no match, return with carry
  144.         inc    bl        ; Is the char > BL
  145.         cmp    al,bl        ; Compare with upper limit
  146.         cmc            ; Invert the carry flag
  147. ChrRng1:
  148.         ret
  149.  
  150. ;█████████████████████████████████████████████████████████████████████████████
  151. ;██                                                                         ██
  152. ;██   Procedure:  Random                                                    ██
  153. ;██                                                                         ██
  154. ;██     To Call:     SP + 4 = High number for random generator              ██
  155. ;██                                                                         ██
  156. ;██        Exit:     AX = Random number between 0 and AX                    ██
  157. ;██                                                                         ██
  158. ;██                  (Taken from Turbo Pascal Random() function)            ██
  159. ;██                                                                         ██
  160. ;█████████████████████████████████████████████████████████████████████████████
  161.  
  162. Random:
  163.         call    Rnd2
  164.         xor    ax,ax
  165.         mov    bx,sp
  166.         mov    bx,ss:[bx+2]
  167.         or    bx,bx
  168.         jz    RndEnd
  169.         xchg    ax,dx
  170.         div    bx
  171.         xchg    ax,dx
  172.   
  173. RndEnd:
  174.         ret    2
  175.  
  176. Rnd2:
  177.         mov    ax,cs:Data_3
  178.         mov    bx,cs:Data_4
  179.         mov    cx,ax
  180.         mul    cs:data_29
  181.         shl    cx,1
  182.         shl    cx,1
  183.         shl    cx,1
  184.         add    ch,cl
  185.         add    dx,cx
  186.         add    dx,bx
  187.         shl    bx,1
  188.         shl    bx,1
  189.         add    dx,bx
  190.         add    dh,bl
  191.         mov    cl,5
  192.         shl    bx,cl
  193.         add    dh,bl
  194.         add    ax,1
  195.         adc    dx,0
  196.         mov    cs:Data_3,ax
  197.         mov    cs:Data_4,dx
  198.         ret
  199.  
  200. Data_29        dw    8405h
  201.  
  202. Data_3        dw    0
  203. Data_4        dw    0
  204.  
  205. ;██████████████████████████████████████████████████████████████████████████
  206. ;██  Int 2Fh - New Handler                                               ██   
  207. ;██████████████████████████████████████████████████████████████████████████
  208.  
  209. Int_2F:
  210.         cmp    ah,0E0h            ; Is this call for us?
  211.         jne    Continue        ; No, Continue with old Int 2Fh
  212.         cmp    al,00h            ; Yes, Is it an installation
  213.         jne    Continue        ;   check?  No, Continue.
  214.         mov    al,0FFh            ; Yes, set al to FFh 
  215.         iret                ; Interrupt Return
  216.     
  217. Continue:
  218.                         ; If not for us, go on
  219.                         ;   to old Int 2Fh.
  220.         db    0EAh
  221. Old_2F_Ofs    dw    ?            ; Old Int 2Fh Offset
  222. Old_2F_Seg    dw    ?            ; Old Int 2Fh Segment
  223.  
  224.  
  225. ;██████████████████████████████████████████████████████████████████████████
  226. ;██  Installation Routine                                                ██   
  227. ;██████████████████████████████████████████████████████████████████████████
  228.  
  229. Install:
  230.         mov    ax,0E000h        ; Call Int 2F to check for 
  231.         int    2Fh            ;   re-installation
  232.         cmp    al,0FFh            ; Is it already installed?
  233.         je    Installed        ; Yes, Print message and quit
  234.         mov    ax,352Fh        ; No, Get old Int 2F to point 
  235.         int    21h            ;   to our Int 2F handler.
  236.         mov    Old_2F_Ofs,bx        ; Save Old Offset
  237.         mov    Old_2F_Seg,es        ; Save Old Segment
  238.  
  239.         mov    ax,3509h        ; Get old Int 09 vector
  240.         int    21h
  241.         mov    Old_09_Ofs,bx        ; Save Old Offset
  242.         mov    Old_09_Seg,es        ; Save Old Segment
  243.  
  244.         call    Randomize        ; Get random number seed
  245.                         ; (based on the time)
  246.  
  247.         mov    ax,cs            ; Point ES to the memory
  248.         sub    ax,0001            ; control block for this 
  249.         mov    es,ax            ; program (KaosKeys).
  250.  
  251.         mov    ax,word ptr es:[0003]    ; Get the size of the memory
  252.         sub    ax,25h            ; block (in paragraphs), and
  253.                         ; subtract 25h paragraphs from
  254.                         ; it (592 bytes).
  255.  
  256.         mov    word ptr es:[0003],ax    ; Replace block size with
  257.                         ; the smaller value
  258.  
  259.         mov    si,word ptr es:[0012h]    ; Get amount of memory in the
  260.                         ; machine (in paragraphs). 
  261.                         ; A000 is 640k
  262.  
  263.         sub    si,25h            ; Subtract 25h paragraphs from
  264.                         ; it.
  265.         mov    es,si            ; Make that the ES
  266.         mov    si,0            ; Point SI and DI to Offset 0
  267.         mov    di,0
  268.  
  269.         mov    cx,500h            ; Move 500h bytes to ES:DI
  270.         rep    movsb            ; which is (A000-25:0) from
  271.                         ; DS:SI which is CS:0
  272.  
  273.         push    es            ; Set DS equal to ES (which
  274.         pop    ds            ; points to the segment where
  275.                         ; we just moved the entire 
  276.                         ; program to)
  277.  
  278.         mov    ax,252Fh        ; Set Int 2F vector to point
  279.         mov    dx,offset Int_2F    ; to our handler at Int_2F
  280.                         ; up towards the top of memory 
  281.         int    21h            ; Set it.
  282.  
  283.         mov    ax,2509h        ; Set keyboard vector to point
  284.         mov    dx,offset Int_09    ; to our handler up towards the
  285.                         ; top of memory
  286.         int    21h            ; Set it.
  287.  
  288.         int    20h            ; And quit normally.
  289.  
  290. Installed:    
  291.         mov    ah,09            ; Print string until '$' or 24h
  292.         mov    dx,offset Message    ; Print data at Message.
  293.         int    21h            ; Print it
  294.         int    20h            ; Quit
  295.  
  296. Randomize:
  297.         mov    ah,2Ch
  298.         int    21h            ; DOS Services  ah=function 2Ch
  299.                         ;  get time, cx=hrs/min, dh=sec
  300.         mov    cs:Data_3,cx
  301.         mov    cs:Data_4,dx
  302.         ret
  303.   
  304. Message        db    'Hidden Kaos - Copyright (C) 1990 - By Philip Maland',00h
  305.         db    0Ah,0Dh,0Ah,0Dh,'Already installed.',0Ah,0Dh,24h
  306.  
  307. Seg_A        ends
  308.   
  309.   
  310.   
  311.         end    Start
  312.  
  313.